﻿#include "procreatedlg.h"
#include "ui_procreatedlg.h"
#include <QSettings>
#include <QTextCodec>
#include <QMessageBox>

ProCreateDlg::ProCreateDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::ProCreateDlg)
{
	ui->setupUi(this);
}

ProCreateDlg::~ProCreateDlg()
{
	delete ui;
}

void ProCreateDlg::on_okBt_clicked()
{
	QString fileName = ui->lineEdit->text();
	if (fileName.isEmpty()){
		return;
	}
	//创建配置文件
    float* fIndex1 = &m_detection.m_Cam1.Scale;
    float* fIndex2 = &m_detection.m_Cam2.Scale;
    int* nIndex1 = &m_detection.m_Cam3.parame0;
    int* nIndex2 = &m_detection.m_Cam4.parame0;



	QString iniFilePath = "Config/Product/" + fileName + ".ini";
	QSettings pIni(iniFilePath, QSettings::IniFormat);
	pIni.setIniCodec(QTextCodec::codecForName("UTF_8"));
	QString sInfo;
	//写入数据
	for (int x = 0; x < 4; x++){
		switch (x) {
        case 0:
			for (int i = 0; i < 17; i++){
				sInfo = QString("Detection_1/parame%1").arg(i);
                pIni.setValue(sInfo, *fIndex1);
                fIndex1++;
			}
			break;
        case 1:
			for (int i = 0; i < 9; i++){
				sInfo = QString("Detection_2/parame%1").arg(i);
                pIni.setValue(sInfo, *fIndex2);
                fIndex2++;
			}
			break;
        case 2:
            for (int i = 0; i < 25; i++){
				sInfo = QString("Detection_3/parame%1").arg(i);
                pIni.setValue(sInfo, *nIndex1);
                nIndex1++;
			}
			break;
        case 3:
            for (int i = 0; i < 25; i++){
				sInfo = QString("Detection_4/parame%1").arg(i);
                pIni.setValue(sInfo, *nIndex2);
                nIndex2++;
			}
			break;
		}
	}

	ui->lineEdit->setText("");
	this->hide();

	QMessageBox::information(this, QString::fromLocal8Bit("成功"), QString::fromLocal8Bit("创建产品成功！"));
	emit sigProCreateToPro(1);

}

void ProCreateDlg::on_noBt_clicked()
{
	this->hide();
}
